<template>
  <HomePanel title="人气推荐" sub-title="人气爆款 不容错过">
    <!-- 绑定被监听的Dom元素(需要的观察容器) -->
    <div style="position: relative;height: 406px;" ref="target">
      <Transition name="fade">
        <ul ref="pannel" class="goods-list" v-if='goods.length'>
          <li v-for="item in goods" :key="item.id">
            <RouterLink to="/">
              <img :src="item.picture" alt="">
              <p class="name">{{item.title}}</p>
              <p class="desc">{{item.alt}}</p>
            </RouterLink>
          </li>
        </ul>
        <HomeSkeleton v-else />
      </Transition>
    </div>
  </HomePanel>
</template>

<script>
import HomePanel from './home-pannel'
// 导入获取展示数据的api接口
import { findHot } from '@/api/home'
// 导入骨架组件
import HomeSkeleton from './home-skeleton'
// 导入懒加载VueUse懒加载监听方法
import Lazy from '@/hooks'
export default {
  name: 'HomeNew',
  components: { HomePanel, HomeSkeleton },
  setup () {
    // 获取懒加载组件 返回的两个值
    // 1、target表示被监听的Dom元素(需要的观察容器)
    // 2、result表示调用接口apiFn返回的数据 (展示数据)
    // 3、需要在懒加载组件传递api接口 用来获取展示数据
    const { result, target } = Lazy(findHot)
    // 返回数据
    return { goods: result, target }
  }
}
</script>

<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 426px;
  li {
    width: 306px;
    height: 406px;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
  }
}
</style>
